package org.htmlparser.tags;

import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import org.htmlparser.Attribute;
import org.htmlparser.Node;
import org.htmlparser.Tag;
import org.htmlparser.nodes.TagNode;
import org.htmlparser.nodes.TextNode;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.SimpleNodeIterator;

public class ObjectTag extends CompositeTag
{
  private static final String[] mEndTagEnders;
  private static final String[] mIds;

  static
  {
    String[] arrayOfString1 = new String[1];
    arrayOfString1[0] = "OBJECT";
    mIds = arrayOfString1;
    String[] arrayOfString2 = new String[2];
    arrayOfString2[0] = "BODY";
    arrayOfString2[1] = "HTML";
    mEndTagEnders = arrayOfString2;
  }

  public Hashtable createObjectParamsTable()
  {
    Hashtable localHashtable = new Hashtable();
    NodeList localNodeList = getChildren();
    if (localNodeList != null)
      for (int i = 0; i < localNodeList.size(); ++i)
      {
        Node localNode = this.children.elementAt(i);
        if (localNode instanceof Tag)
        {
          Tag localTag = (Tag)localNode;
          if (localTag.getTagName().equals("PARAM"))
          {
            String str1 = localTag.getAttribute("NAME");
            if ((str1 != null) && (str1.length() != 0))
            {
              String str2 = localTag.getAttribute("VALUE");
              localHashtable.put(str1.toUpperCase(), str2);
            }
          }
        }
      }
    return localHashtable;
  }

  public String[] getEndTagEnders()
  {
    return mEndTagEnders;
  }

  public String[] getIds()
  {
    return mIds;
  }

  public String getObjectClassId()
  {
    return getAttribute("CLASSID");
  }

  public String getObjectCodeBase()
  {
    return getAttribute("CODEBASE");
  }

  public String getObjectCodeType()
  {
    return getAttribute("CODETYPE");
  }

  public String getObjectData()
  {
    return getAttribute("DATA");
  }

  public String getObjectHeight()
  {
    return getAttribute("HEIGHT");
  }

  public Hashtable getObjectParams()
  {
    return createObjectParamsTable();
  }

  public String getObjectStandby()
  {
    return getAttribute("STANDBY");
  }

  public String getObjectType()
  {
    return getAttribute("TYPE");
  }

  public String getObjectWidth()
  {
    return getAttribute("WIDTH");
  }

  public String getParameter(String paramString)
  {
    return ((String)(String)getObjectParams().get(paramString.toUpperCase()));
  }

  public Enumeration getParameterNames()
  {
    return getObjectParams().keys();
  }

  public void setObjectClassId(String paramString)
  {
    setAttribute("CLASSID", paramString);
  }

  public void setObjectCodeBase(String paramString)
  {
    setAttribute("CODEBASE", paramString);
  }

  public void setObjectCodeType(String paramString)
  {
    setAttribute("CODETYPE", paramString);
  }

  public void setObjectData(String paramString)
  {
    setAttribute("DATA", paramString);
  }

  public void setObjectHeight(String paramString)
  {
    setAttribute("HEIGHT", paramString);
  }

  public void setObjectParams(Hashtable paramHashtable)
  {
    NodeList localNodeList = getChildren();
    if (localNodeList == null)
    {
      localNodeList = new NodeList();
      Enumeration localEnumeration = paramHashtable.keys();
      while (true)
      {
        if (!(localEnumeration.hasMoreElements()))
          break label280;
        Vector localVector = new Vector();
        String str1 = (String)localEnumeration.nextElement();
        String str2 = (String)paramHashtable.get(str1);
        localVector.addElement(new Attribute("PARAM", null));
        localVector.addElement(new Attribute(" "));
        localVector.addElement(new Attribute("VALUE", str2, '"'));
        localVector.addElement(new Attribute(" "));
        localVector.addElement(new Attribute("NAME", str1.toUpperCase(), '"'));
        localNodeList.add(new TagNode(null, 0, 0, localVector));
      }
    }
    int i = 0;
    while (true)
    {
      while (true)
      {
        while (true)
        {
          Node localNode2;
          do
          {
            do
            {
              if (i >= localNodeList.size());
              Node localNode1 = localNodeList.elementAt(i);
              if (!(localNode1 instanceof Tag))
                break label274;
              if (!(((Tag)localNode1).getTagName().equals("PARAM")))
                break label268;
              localNodeList.remove(i);
            }
            while (i >= localNodeList.size());
            localNode2 = localNodeList.elementAt(i);
          }
          while ((!(localNode2 instanceof TextNode)) || (((TextNode)localNode2).getText().trim().length() != 0));
          localNodeList.remove(i);
        }
        label268: ++i;
      }
      label274: ++i;
    }
    label280: setChildren(localNodeList);
  }

  public void setObjectStandby(String paramString)
  {
    setAttribute("STANDBY", paramString);
  }

  public void setObjectType(String paramString)
  {
    setAttribute("TYPE", paramString);
  }

  public void setObjectWidth(String paramString)
  {
    setAttribute("WIDTH", paramString);
  }

  public String toString()
  {
    int j;
    Node localNode;
    StringBuffer localStringBuffer = new StringBuffer(500);
    localStringBuffer.append("Object Tag\n");
    localStringBuffer.append("**********\n");
    localStringBuffer.append("ClassId = ");
    localStringBuffer.append(getObjectClassId());
    localStringBuffer.append("\n");
    localStringBuffer.append("CodeBase = ");
    localStringBuffer.append(getObjectCodeBase());
    localStringBuffer.append("\n");
    localStringBuffer.append("CodeType = ");
    localStringBuffer.append(getObjectCodeType());
    localStringBuffer.append("\n");
    localStringBuffer.append("Data = ");
    localStringBuffer.append(getObjectData());
    localStringBuffer.append("\n");
    localStringBuffer.append("Height = ");
    localStringBuffer.append(getObjectHeight());
    localStringBuffer.append("\n");
    localStringBuffer.append("Standby = ");
    localStringBuffer.append(getObjectStandby());
    localStringBuffer.append("\n");
    localStringBuffer.append("Type = ");
    localStringBuffer.append(getObjectType());
    localStringBuffer.append("\n");
    localStringBuffer.append("Width = ");
    localStringBuffer.append(getObjectWidth());
    localStringBuffer.append("\n");
    Hashtable localHashtable = getObjectParams();
    Enumeration localEnumeration = localHashtable.keys();
    if (localEnumeration == null)
    {
      localStringBuffer.append("No Params found.\n");
      j = 0;
      SimpleNodeIterator localSimpleNodeIterator = children();
      do
      {
        if (!(localSimpleNodeIterator.hasMoreNodes()))
          break label413;
        localNode = localSimpleNodeIterator.nextNode();
      }
      while ((localNode instanceof Tag) && (((Tag)localNode).getTagName().equals("PARAM")));
      if (j != 0)
        break label403;
      localStringBuffer.append("Miscellaneous items :\n");
    }
    while (true)
    {
      while (true)
      {
        j = 1;
        localStringBuffer.append(localNode.toString());
      }
      int i = 0;
      while (true)
      {
        if (!(localEnumeration.hasMoreElements()));
        String str1 = (String)localEnumeration.nextElement();
        String str2 = (String)localHashtable.get(str1);
        localStringBuffer.append(i);
        localStringBuffer.append(": Parameter name = ");
        localStringBuffer.append(str1);
        localStringBuffer.append(", Parameter value = ");
        localStringBuffer.append(str2);
        localStringBuffer.append("\n");
        ++i;
      }
      label403: localStringBuffer.append(" ");
    }
    if (j != 0)
      label413: localStringBuffer.append("\n");
    localStringBuffer.append("End of Object Tag\n");
    localStringBuffer.append("*****************\n");
    return localStringBuffer.toString();
  }
}